var express = require('express');
var router = express.Router();

// 配置数据库引擎
const modle = require("../modle/db")
// 连结地址
let src=require("../config/index")

router.get('/detail', async (req, res) => { 
    let { cid = "" } = req.query
     console.log(cid)
    let sql1 = `select id,cid,title,price,concat("${src}","/uploads/course/",image_src) as image_src,intro, concat("${src}","/uploads/course/",detail_imgs) as detail_imgs,type,type_name,area_name,grade_name,subject_name,category_name,tid,status from e_course where cid="${cid}"`
    let [err, result1] = await modle.query(sql1)

        //视频数据
        let sql2 = `select id,cid,vnum,concat("${src}","/uploads/video/",video_src) as video_src,video_title from e_video where cid="${cid}" order by vnum desc`;
        let [err2, result2] = await modle.query(sql2);
        //console.log(result2)
        //查询老师数据
        let sql3 = `select id,tid,realname,intro,concat("${src}","/uploads/avatar/",head_photo_url) as head_photo_url from e_teacher where tid="${result1[0].tid}"`;
        let [err3, result3] = await modle.query(sql3);
        //console.log(result3)
        let data = {
            "code": "200",
            "msg": "查询成功",
            "result": {
                course: result1[0],//查询课程数据表
                video: result2,//查询视频列表
                teacher: result3[0]//查询老师数据
            }
        }
        res.send(data);
})


module.exports = router;